<template>
  <div id="pageDialog">
    <el-dialog
      :title="dialogMsg.title || ''"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <span>{{dialogMsg.msg}}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="info" v-show="cancelVisible" @click="dialogVisible = false;cancelMethod()">取消</el-button>
    <el-button type="primary" @click="dialogVisible = false;closeMethod()">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
  // 用于页面提示
  import {bus} from '../../js/brothersBus'

  export default {
    name: 'pageDialog',
    data() {
      return {
        dialogVisible: false,
        cancelVisible: false,
        dialogMsg: {
          msg: '这是一段文字信息',
          title: '提示'
        },
      };
    },
    mounted() {
      bus.$on('showDialog', (arg) => {
        this.dialogVisible = true; // 接收
        if (typeof(arg) === 'string') {
          this.dialogMsg.msg = arg;
        } else {
          this.dialogMsg = arg; // 接收
          if (arg.cancel) {
            this.cancelVisible = true;
          }
          if (arg.cb) {
            this.closeMethod = () => {
              this.dialogVisible = false;
              arg.cb()
            }
          }
          ;
        }
      })
    },
    methods: {
      handleClose(done) {
        this.closeMethod()
      },
      // 点击确定时关闭弹窗、可能有后续操作
      closeMethod() {
      },

      // 点击取消时关闭弹窗、无后续操作
      cancelMethod() {
      }
    }
  };
</script>
